package se.lth.student.axisandroidcam.client;

import java.util.Observable;

import android.text.style.UpdateAppearance;

import se.lth.cs.fakecamera.Axis211A;

public class Camera {
	private int cameraNbr, cameraType;
	private byte[] pic;
	private PrivateObserver observer;
	public final static int FAKE_CAMERA = 0;
	public final static int PROXY_CAMERA = 1;
	public final static int SERVER_CAMERA = 2;
	
	public Camera(int cameraNbr, int cameraType){
		this.cameraNbr = cameraNbr;
		this.cameraType = cameraType;
		observer = new PrivateObserver();
	}
	
	
	
	public synchronized void setPicture(byte[] data){
		pic = new byte[data.length];
		System.arraycopy(data, 0, pic, 0, data.length);
		observer.update(pic, cameraNbr);	
	}
	
	
	private class PrivateObserver extends Observable{
	    
		public void update(byte[] data, int cameraNbr){
			DataWrapper wrapper = new DataWrapper(data, cameraNbr);
			setChanged();
			notifyObservers(wrapper);
		}
	}
	
	public int getId(){
		return cameraNbr;
	}
	
	@Override
	public String toString(){
		String s = "Camera "+cameraNbr+" (";
		switch(cameraType){
		case Camera.FAKE_CAMERA:
			s += "Fake Camera)";
			break;
		case Camera.PROXY_CAMERA:
			s += "Proxy Camera)";
			break;
		case Camera.SERVER_CAMERA:
			s += "Server Camera)";
			break;
		}
		return s;
	}
	
}
